package plus.ldl.ldltest.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import plus.ldl.ldltest.pojo.User;
import plus.ldl.ldltest.service.UserService;

import java.util.List;

/**
 * @author ldl.plus
 * @date 2020年04月27日  20:44
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping
    public List<User> findAll() {
        return userService.findAll();
    }

    @PostMapping
    public String add(@RequestBody User user) {
        userService.add(user);
        return "ok";
    }

    @DeleteMapping("/{id}")
    public String delete(@PathVariable Integer id) {
        userService.deleteById(id);
        return "ok";
    }

    /**
     * 更新User的全部信息
     *
     * @param user
     * @return
     */
    @PutMapping
    public String updateById(@RequestBody User user) {
        userService.updateById(user);
        return "ok";
    }
}
